﻿using System;
using System.Collections.Generic;
using System.Data;

namespace Tuto.DAL
{
    class Livre
    {
        /// <summary>
        ///     Create a new object in the database
        /// </summary>
        /// <param name="fields"></param>
        /// <returns></returns>
        public  int create(Dictionary<string, object > fields)
        {
            int result = DALObject.runSQLInsert("tuto_livre", fields);
            return result;
        }

        /// <summary>
        ///    Updates the object
        /// </summary>
        /// <param name="fields"></param>
        /// <param name="livreId"></param>
        /// <returns></returns>
        public int update(Dictionary<string, object> fields ,int livreId)
        {
            int result = DALObject.runSQLUpdate("tuto_livre", fields, livreId);
            return result;
        }

        /// <summary>
        ///     Reads an object
        /// </summary>
        /// <param name="livreId"></param>
        /// <returns></returns>
        public DataSet read(int livreId)
        {
            DataSet _dataSet = new DataSet();

            List<string> table = new List<string>();
            table.Add("tuto_livre");
            List<string> cols = new List<string>();
            List<string> num_ops = new List<string>();
            num_ops.Add("=");
            List<string> log_ops = new List<string>();
            Dictionary<string, object> constrainte = new Dictionary<string, object>();
            constrainte.Add("id", livreId);

            _dataSet = DALObject.runSQLSelect(table, cols, constrainte, num_ops, log_ops);

            return _dataSet;
        }

        /// <summary>
        ///     Deletes an object
        /// </summary>
        /// <param name="livreId"></param>
        /// <returns></returns>
        public  int delete(int livreId)
        {
            Dictionary<string, object> constrainte = new Dictionary<string, object>();
            constrainte.Add("id", livreId);
            List<string> num_ops = new List<string>();
            num_ops.Add("=");
            List<string> log_ops = new List<string>();

            int result = DALObject.runSQLDelete("tuto_livre", constrainte, num_ops, log_ops);

            return result;
        }
    }
}
